home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
WINDOWS
/
SSHEET.ARJ
/
GENERIC.C
next >
Wrap
C/C++ Source or Header
|
1992-04-04
|
13KB
|
383 lines
/*
* This program is an introduction to using the Spread Sheet custom
* control DLL.
*
* Both this program and the demo custom control DLL are shareware. You
* may copy and distribute them both freely. However, if you intend to
* use either of them as part of an application you'll need to register
* them. To register:
*
* 1. Fill out the registeration form and fax it to us
* The fax number is: 714-937-5830
* or
* 2. Write to us through CompuServ, Id: 72520,2325
*
* You can buy the complete DLL or the full source for $29,99 and $49.99
* respectively. To order, send check or money order to
*
*
* A. SHADMAN CO., P.O. BOX 28494, SANTA ANA, CA 92799-8494
*
*
* Legal notice:
*
* We are granting a license to you to execute this program and the
* accomponying DLL for evaluation purposes only.
*
* WE MAKE NO WARRANTY OR REPRESENTATION, EITHER EXPRESS OR IMPLIED
* WITH RESPECT TO THIS AND THE CUSTOM CONTROL DLL, INCLUDING THE
* QUALITY, PERFORMANCE, MERCHANTIBILITY OR FITNESS FOR A PARTICULAR
* PURPOSE.
*
* Becuase of the complex nature of computer software this program or
* the custom control DLL may not be completely free of errors.
* You agree to take full responsibility for verification of any work
* that includes either this program or the custom control DLL.
* IN NO EVENT WILL A. SHADMAN CO. BE RESPONSIBLE FOR DIRECT, INDIRECT,
* SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
* USE OR INABILITY TO USE THIS PROGRAM OR THE CUSTOM CONTROL DLL.
*
* This program is based on the GENERIC program included with the
* Microsoft Windows SDK.
*/
#include <windows.h>
#include <string.h>
#include "generic.h"
#include "sshthdr.h"
BOOL InitSSheetData(VOID) ;
VOID CreateDummySSheetData(HWND) ;
HANDLE hInst; /* current instance */
HWND hWndSSht, hWndEdt, hWndButt ;
int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
HANDLE hInstance; /* current instance */
HANDLE hPrevInstance; /* previous instance */
LPSTR lpCmdLine; /* command line */
int nCmdShow; /* show-window type (open/icon) */
{
MSG msg; /* message */
if (!hPrevInstance) /* Other instances of app running? */
if (!InitApplication(hInstance)) /* Initialize shared things */
return (FALSE); /* Exits if unable to initialize */
/* Perform initializations that apply to a specific instance */
if (!InitInstance(hInstance, nCmdShow))
return (FALSE);
/* Acquire and dispatch messages until a WM_QUIT message is received. */
while (GetMessage(&msg, /* message structure */
NULL, /* handle of window receiving the message */
NULL, /* lowest message to examine */
NULL)) /* highest message to examine */
{
TranslateMessage(&msg); /* Translates virtual key codes */
DispatchMessage(&msg); /* Dispatches message to window */
}
return (msg.wParam); /* Returns the value from PostQuitMessage */
}
BOOL InitApplication(hInstance)
HANDLE hInstance; /* current instance */
{
WNDCLASS wc;
/* Fill in window class structure with parameters that describe the */
/* main window. */
wc.style = NULL; /* Class style(s). */
wc.lpfnWndProc = MainWndProc; /* Function to retrieve messages for */
/* windows of this class. */
wc.cbClsExtra = 0; /* No per-class extra data. */
wc.cbWndExtra = 0; /* No per-window extra data. */
wc.hInstance = hInstance; /* Application that owns the class. */
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = "GenericMenu"; /* Name of menu resource in .RC file. */
wc.lpszClassName = "GenericWClass"; /* Name used in call to CreateWindow. */
/* Register the window class and return success/failure code. */
return (RegisterClass(&wc));
}
BOOL InitInstance(hInstance, nCmdShow)
HANDLE hInstance; /* Current instance identifier. */
int nCmdShow; /* Param for first ShowWindow() call. */
{
HWND hWnd; /* Main window handle. */
/* Save the instance handle in static variable, which will be used in */
/* many subsequence calls from this application to Windows. */
hInst = hInstance;
/* Create a main window for this application instance. */
hWnd = CreateWindow(
"GenericWClass", /* See RegisterClass() call. */
"SSHEET Sample Application", /* Text for window title bar. */
WS_OVERLAPPEDWINDOW, /* Window style. */
CW_USEDEFAULT, /* Default horizontal position. */
CW_USEDEFAULT, /* Default vertical position. */
CW_USEDEFAULT, /* Default width. */
CW_USEDEFAULT, /* Default height. */
NULL, /* Overlapped windows have no parent. */
NULL, /* Use the window class menu. */
hInstance, /* This instance owns this window. */
NULL /* Pointer not needed. */
);
/* If window could not be created, return "failure" */
if (!hWnd)
return (FALSE);
/* Make the window visible; update its client area; and return "success" */
ShowWindow(hWnd, nCmdShow); /* Show the window */
UpdateWindow(hWnd); /* Sends WM_PAINT message */
return (TRUE); /* Returns the value from PostQuitMessage */
}
long FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
HWND hWnd; /* window handle */
unsigned message; /* type of message */
WORD wParam; /* additional information */
LONG lParam; /* additional information */
{
FARPROC lpProcAbout; /* pointer to the "About" function */
static HANDLE hLib ;
static GLOBALHANDLE hSSheetData ;
SSHTCREATESTRUCT SSheetData ;
char buffer[255] ;
switch (message) {
case WM_CREATE:
//
// Load the Custom Control Library.
// Loading the library registers the controls class: TABL CTRL.
//
hLib = LoadLibrary("SSHTCTRL.DLL") ;
if (hLib < 32)
return (0) ;
// The control's id string must be copied into
// the create structure.
strcpy(SSheetData.szID, SSHEETID) ;
SSheetData.nRows = 10 ; // In demo version limited to 10
SSheetData.nCols = 7 ; // In demo version limited to 7
SSheetData.nColAnchor = 0 ;
SSheetData.nRowAnchor = 0 ;
SSheetData.nCurrentCol = 0 ;
SSheetData.nCurrentRow = 0 ;
hWndSSht = CreateWindow(
CLASS_SSHEET,
NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER,
50,
50,
400,
200,
hWnd,
1000,
hInst,
(LPSTR)&SSheetData);
// customize SSheet with headings, cell alignment etc.
if (!InitSSheetData())
return (FALSE) ;
// put some data in SSheet
CreateDummySSheetData(hWndSSht) ;
hWndEdt = CreateWindow(
"EDIT",
NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,
10,
10,
200,
30,
hWnd,
2000,
hInst,
NULL);
hWndButt = CreateWindow(
"BUTTON",
NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | BS_PUSHBUTTON,
220,
10,
120,
30,
hWnd,
3000,
hInst,
NULL);
SetWindowText(hWndButt,"Set Cell Value") ;
return (0) ;
case WM_RBUTTONDOWN:
SendMessage(hWndSSht,
SS_SETCELLDATA, MAKEROWCOL(3,0), (LONG)"HI!") ;
SendMessage(hWndSSht, SS_DISPLAYCELL, MAKEROWCOL(3,0), NULL) ;
return (0) ;
case WM_COMMAND: /* message: command from application menu */
switch (wParam)
{
case IDM_ABOUT:
lpProcAbout = MakeProcInstance(About, hInst);
DialogBox(hInst, /* current instance */
"AboutBox", /* resource to use */
hWnd, /* parent handle */
lpProcAbout); /* About() instance address */
FreeProcInstance(lpProcAbout);
return (0) ;
case 3000: // button
{
int nRow, nCol ;
char buffer[255] ;
nRow = SendMessage(hWndSSht, SS_GETCURROW, NULL, NULL) ;
nCol = SendMessage(hWndSSht, SS_GETCURCOL, NULL, NULL) ;
memset(buffer,'\0', sizeof(buffer)) ;
GetWindowText(hWndEdt, buffer, 254) ;
SendMessage(hWndSSht,
SS_SETCELLDATA, MAKEROWCOL(nRow,nCol),
(LONG)buffer) ;
SendMessage(hWndSSht, SS_DISPLAYCELL, MAKEROWCOL(nRow,nCol),
NULL) ;
return (0) ;
}
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
case WM_DESTROY: /* message: window being destroyed */
FreeLibrary(hLib) ;
if (hSSheetData)
GlobalFree(hSSheetData) ;
PostQuitMessage(0);
break;
// SSHEET sends messages to its parent
case SSN_NEWCELL:
{
int nRow, nCol ;
nRow = SendMessage(hWndSSht, SS_GETCURROW, NULL, NULL) ;
nCol = SendMessage(hWndSSht, SS_GETCURCOL, NULL, NULL) ;
memset(buffer,'\0',sizeof(buffer)) ;
SendMessage(hWndSSht, SS_GETCELLDATA, MAKEROWCOL(nRow,nCol),
(LONG)buffer) ;
SetWindowText(hWndEdt,buffer) ;
return (0) ;
}
default: /* Passes it on if unproccessed */
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return (NULL);
}
BOOL FAR PASCAL About(hDlg, message, wParam, lParam)
HWND hDlg; /* window handle of the dialog box */
unsigned message; /* type of message */
WORD wParam; /* message-specific information */
LONG lParam;
{
switch (message) {
case WM_INITDIALOG: /* message: initialize dialog box */
return (TRUE);
case WM_COMMAND: /* message: received a command */
if (wParam == IDOK /* "OK" box selected? */
|| wParam == IDCANCEL) { /* System menu close command? */
EndDialog(hDlg, TRUE); /* Exits the dialog box */
return (TRUE);
}
break;
}
return (FALSE); /* Didn't process a message */
}
BOOL InitSSheetData()
{
LOGFONT lf ;
// SSHEET defualt font CAN'T be a stock font because
// its deleted automaticaly by the control
GetObject(GetStockObject(ANSI_VAR_FONT), sizeof(lf), &lf) ;
lf.lfItalic = TRUE ;
SendMessage(hWndSSht, SS_SETDEFFONT,
(WORD)CreateFontIndirect(&lf), NULL) ;
SendMessage(hWndSSht, SS_SETCOLTITLE, 0, (LONG)"Member#") ;
SendMessage(hWndSSht, SS_SETCOLTITLE, 1, (LONG)"Home Church") ;
SendMessage(hWndSSht, SS_SETCOLTITLE, 2, (LONG)"Age") ;
SendMessage(hWndSSht, SS_SETCOLTITLE, 3, (LONG)"Position") ;
SendMessage(hWndSSht, SS_SETCOLTITLE, 4, (LONG)"Activity") ;
SendMessage(hWndSSht, SS_SETCOLTITLE, 5, (LONG)"Date Joined") ;
SendMessage(hWndSSht, SS_SETCOLTITLE, 6, (LONG)"Date Baptized") ;
SendMessage(hWndSSht, SS_SETCOLWIDTH, 0, MAKELONG(20,20+1)) ;
SendMessage(hWndSSht, SS_SETCOLWIDTH, 1, MAKELONG(20,40+1)) ;
SendMessage(hWndSSht, SS_SETCOLWIDTH, 2, MAKELONG(10,10+1)) ;
SendMessage(hWndSSht, SS_SETCOLWIDTH, 3, MAKELONG(20,40+1)) ;
SendMessage(hWndSSht, SS_SETCOLWIDTH, 4, MAKELONG(20,40+1)) ;
SendMessage(hWndSSht, SS_SETCOLWIDTH, 5, MAKELONG(10,20+1)) ;
SendMessage(hWndSSht, SS_SETCOLWIDTH, 6, MAKELONG(10,20+1)) ;
SendMessage(hWndSSht, SS_SETCOLJUST, 0, COLJUST_CENTER) ;
SendMessage(hWndSSht, SS_SETCOLJUST, 1, COLJUST_CENTER) ;
SendMessage(hWndSSht, SS_SETCOLJUST, 2, COLJUST_RIGHT) ;
SendMessage(hWndSSht, SS_SETCOLJUST, 3, COLJUST_CENTER) ;
SendMessage(hWndSSht, SS_SETCOLJUST, 4, COLJUST_CENTER) ;
SendMessage(hWndSSht, SS_SETCOLJUST, 5, COLJUST_LEFT) ;
SendMessage(hWndSSht, SS_SETCOLJUST, 6, COLJUST_LEFT) ;
// initialize SSHEET data areas, TRUE if succeeded, else FALSE
return (SendMessage(hWndSSht, SS_INITSSHEET, NULL, NULL)) ;
}
VOID CreateDummySSheetData(HWND hWndSSheet)
{
int i ;
char buffer[30] ;
for (i=0; i <10; i++)
{
wsprintf (buffer, "%05d", i) ;
SendMessage(hWndSSheet, SS_SETCELLDATA, MAKEROWCOL(i,0), (LONG)buffer) ;
}
}